<?php
    class AdminAccessAssertion implements Zend_Acl_Assert_Interface
    {        
        
        public function assert(Zend_Acl $acl,
                               Zend_Acl_Role_Interface $role = null,
                               Zend_Acl_Resource_Interface $resource = null,
                               $privilege = null)
        {
            return $this->_isAllowedTable();
        }
    
        protected function _isAllowedTable() {
            $ci = &get_instance();            
            $curtable = ($ci->uri->segment(4) == FALSE) ? 'dashboard' : $ci->uri->segment(4);            
            if($ci->system->getRole('rolename') == 'manager') {
                $tables = array('orders_montag', 'stuff', 'orders_montag','orders_devices');
            }
            
            if($ci->system->getRole('rolename') == 'administrator') {
                $tables = array('tree','stuff','users','orders_montag','orders_devices','config');
            }
            
            $tables[] = 'dashboard';
            foreach($tables as $table) {
                $ci->system->allow($table);
            }
            
            if(in_array($curtable, $tables)) {
                return TRUE;
            }
            
            return FALSE;
        }
    }
?>
